<?php

//商品控制器
class GoodsController extends Controller{
	private $model;
	
	public function __init(){
		$this->model=K('Goods');
	}
	
	public function index(){
		$gid=Q('get.gid',0,'intval');
		$goods=$this->model->where("gid={$gid}")->find();
	    $this->assign('goods',$goods);
		$detail=K('Detail')->where("gid={$gid}")->find();
		$this->assign('detail',$detail);
		
	    //尺码和颜色
	    $spec=M()->join("__attr__ a JOIN __goods_attr__ ga ON a.taid=ga.taid")->where("class=1 AND gid={$gid}")->all();
		$temp = array();
		foreach ($spec as $k => $v) {
			$temp[$v['taid']]['taname']=$v['taname'];
			$temp[$v['taid']]['gtvalue'][$v['gtid']]=$v['gtvalue'];
		}
		$this->assign('temp',$temp);
		
		//商品总库存
		$number=M('goods_list')->where("gid={$gid}")->sum('number');
		
		$this->assign('number',$number);
		
		//异步查询库存
		if(IS_AJAX){
			$combine=Q('post.');
			$combine=$combine['combine'];
			$combine=rtrim($combine, ",");
			
			$num=K('Goodslist')->where("combine='{$combine}'")->find();
			$num=$num['number'];

			$this->ajax($num);
		}
		
		
		$this->display();
	}
	
	
	
}

?>
